 /*///////////////////////////////////////////////////////////////////////////////
-- Author:      liuhx
-- Created:     Thu Nov 15 17:12:41 CST 2018
-- Description:
-- If you have any question,please email to liuhx@gentlesoft.com.cn
////////////////////////////////////////////////////////////////////////////////*/
package com.ctsi.product.service;

 import com.ctsi.commons.util.UtilValidate;
 import com.ctsi.commons.util.id.UUIDGenerator;
 import com.ctsi.commons.util.response.Page;
 import com.ctsi.framework.mybatis.support.MybatisGenericDao;
 import com.ctsi.product.entity.DianzanNumber;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;

 import java.util.List;
 import java.util.Map;


/**
 * DianzanNumber Service 类
 * @author   liuhx
 * @description  DianzanNumber
 * @created	 Thu Nov 15 17:12:41 CST 2018
 */

@Service
public class DianzanNumberService {
	private static final Logger logger=LoggerFactory.getLogger(DianzanNumberService.class);
	@Autowired
	private MybatisGenericDao dao;


/**
 * 查询某产品点赞数量
 */
public  Object  selectDianZanNumByProductId(String productId){
		logger.debug("selectDianZanNumByProductId {}",productId);
	return 	 dao.queryForObject(DianzanNumber.class.getName() + ".selectDianZanNumByProductId", productId);
}
/**
 * 查询某产品收藏数量selectSCNumByProductId
 */
public  Object  selectSCNumByProductId(String productId){
	logger.debug("selectSCNumByProductId {}",productId);
	return 	 dao.queryForObject(DianzanNumber.class.getName() + ".selectSCNumByProductId", productId);
}
/**
 * 查询个人收藏数量
 */

	/**
	 * 每次点赞都会生成一条数据记录
	 */
	public int insertDianzanNumber(DianzanNumber dianzanNumber){
		if(UtilValidate.isEmpty(dianzanNumber.getId()))
			dianzanNumber.setId(UUIDGenerator.getId());
		logger.debug("insert {}",dianzanNumber);
	return 	dao.insert(dianzanNumber);
	}
	/**
	 * 点击收藏添加一条记录
	 */
	public int insertCollect(DianzanNumber dianzanNumber){
		if(UtilValidate.isEmpty(dianzanNumber.getId()))
			dianzanNumber.setId(UUIDGenerator.getId());
		logger.debug("insertCollect {}",dianzanNumber);
		return 	dao.insertCollect(dianzanNumber);
	}
	/**
	 * 动态更新
	 */
	public int updateDianzanNumberByPKSelective(DianzanNumber dianzanNumber){
		logger.debug("updateByPrimaryKeySelective {}",dianzanNumber);
		return dao.update(DianzanNumber.class.getName()+".updateByPrimaryKeySelective", dianzanNumber);
	}
	/**
	 * 更新
	 */
	public int updateDianzanNumber(DianzanNumber dianzanNumber){
		logger.debug("update {}",dianzanNumber);
		return dao.update(dianzanNumber);
	}


	public DianzanNumber editDianzanNumberById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("editById {}",id);
		return (DianzanNumber)dao.queryForObject(DianzanNumber.class.getName()+".edit", id);
	}
	/**
	 * 根据ID查找 DianzanNumber对象
	 */
	public DianzanNumber findDianzanNumberById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(DianzanNumber.class, id);
	}
	/**
	 * 删除DianzanNumber对象
	 */
	public int removeDianzanNumber(String id){
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(DianzanNumber.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}

	/**
	 * 详细页查询
	 */
		public DianzanNumber findByDetail(String id){
		return (DianzanNumber)dao.queryForObject(DianzanNumber.class.getName()+".findByDetail",id);
	}
	/**
	 * 多条件查询结果
	 */
	public Page<DianzanNumber> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(DianzanNumber.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 多条件查询结果不分页
	 */
	public List<DianzanNumber> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<DianzanNumber>)dao.queryForList(DianzanNumber.class.getName()+".selectByMap",map);
	}
	/*
	* 查询该用户是否点赞
	* */
	public int selectIsDianZanCount(DianzanNumber dianzanNumber){
        logger.debug("selectIsDianZanCount {}",dianzanNumber);
        Integer integer = (Integer) dao.queryForObject(DianzanNumber.class.getName() + ".selectIsDianZanCount", dianzanNumber);
        return  integer;
    }
    /*
     * 查询该用户是否点赞1
     * */
    public int selectIsDianZanCount1(DianzanNumber dianzanNumber){
        logger.debug("selectIsDianZanCount1 {}",dianzanNumber);
        Integer integer = (Integer) dao.queryForObject(DianzanNumber.class.getName() + ".selectIsDianZanCount1", dianzanNumber);
        return  integer;
    }
    /*
    * 查询id,is_dianzan
    * */
    public DianzanNumber selectIsDianZan(DianzanNumber dianzanNumber){
        logger.debug("selectIsDianZan {}",dianzanNumber);
		return (DianzanNumber) dao.queryForObject(DianzanNumber.class.getName()+".selectIsDianZan",dianzanNumber);
	}

	/**
	 * 查询该用户是否已收藏产品文档
	 * @param dianzanNumber
	 * @return
	 */
	public int selectIsCollect(DianzanNumber dianzanNumber){
		logger.debug("selectIsCollect {}",dianzanNumber);
		return (int) dao.queryForObject(DianzanNumber.class.getName()+".selectIsCollect",dianzanNumber);
	}
    /*
    * 修改is_dianzan
    * */
    public int updateIsDianZan(DianzanNumber dianzanNumber){
        logger.debug("updateIsDianZan {}",dianzanNumber);
        return dao.update(DianzanNumber.class.getName()+".updateIsDianZan", dianzanNumber);
    }

}
